<!--
 * @Author: WangShuai 1830773767@qq.com
 * @Date: 2025-05-29 11:05:50
 * @LastEditors: WangShuai 1830773767@qq.com
 * @LastEditTime: 2025-05-29 14:01:41
 * @FilePath: \guanggu_traffic\src\views\normal\components\CheckNotice.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%A
-->
<template>
	<el-menu-item index="5" @click="handleCheckNotice">查看公告</el-menu-item>
	<el-dialog
		title=""
		:visible.sync="dialogOverflowVisible"
		width="500"
		draggable
		overflow
	>
		<div class="dialogContent">
			<p>公告发布时间</p>
			<span>zzzz</span>
			<p>公告发布内容</p>
			<span>zzzzzz</span>
		</div>
		<template #footer>
			<div class="dialog-footer">
				<el-button @click="dialogOverflowVisible = false">取 消</el-button>
				<el-button :plain="true"  type="primary" @click="dialogOverflowVisible = false"
					>确 定</el-button
				>
			</div>
		</template>
	</el-dialog>
</template>

<script setup>
import {reactive,ref} from 'vue'
import {getNoticeHttp} from'@/request/request'
import { ElMessage } from 'element-plus';
const dialogOverflowVisible = ref(false);
const noiceInfo = reactive({})
//获取公告信息
const handleCheckNotice = ()=>{
    getNoticeHttp().then((res)=>{
        dialogOverflowVisible.value = true;
        //获取最新公告
        noiceInfo = getLastNotice(res.data)
    }).catch((err)=>{
        ElMessage.error('获取公告信息失败');
    })
}
//获取最新的公告信息
const getLastNotice = (noticeArr)=>{
let latestNotice = {};
//根据时间获取最新公告 时间格式为"2024/9/29/ 11:18:36" 字符串
//获取时间戳
let latestTime = new Date("1990/1/1 0:0:0").getIime();
    for(let i=0; i<noticeArr.length;i++){
        let timeStamp = new Date(noticeArr[i].time).getTime();
        if(timeStamp > latestTime){
            latestNotice = noticeArr[i];
            latestTime = timeStamp;
        }
    }
    return latestNotice;
}
</script>

<style lang="scss" scoped></style>
